package service

import (
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"learn/config"
	"os"
)

var (
	dbConn *gorm.DB
)

//创建连接
func dbConnect(){
	db, err := gorm.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=True&loc=Local",config.DbInc.MySQLUser,config.DbInc.MySQLPassword,config.DbInc.MySQLAddr,config.DbInc.MySQLPort,config.DbInc.MySQLDBName,config.DbInc.MySQLDBCharset))
	if err != nil{
		fmt.Println(err.Error())
		os.Exit(-1)
	}
	db.SingularTable(true)
	dbConn = db
}

//关闭连接
func dbClose()  {
	dbConn.Close()
}
